package com.neuedu.web.dao;

import com.neuedu.web.common.BaseDao;
import com.neuedu.web.po.UploadPO;
import com.neuedu.web.po.UploadPO;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * @author 金山
 * 项目：jdbc-dao
 * site: https://blog.fulfill.com.cn
 * 描述  dept 表的数据访问对象
 * @data  2024年11月21日13:38:03
 */
public class UploadDao extends BaseDao<UploadPO> {



    public List<UploadPO> selectAll(  String sql, Object... params) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        return super.selectAll(UploadPO.class , sql,params);
    }
    public List<UploadPO> selectPage( int current, int size, String sql, Object... params) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        return super.selectPage(UploadPO.class , current ,size,sql,params);
    }



    public UploadPO selectById(long id) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {


        String sql = "select * from upload where upload_id= ?";
        return super.selectOne(UploadPO.class,sql,id);

    }



    public int insert(UploadPO po) {
        String sql = "INSERT INTO `upload` (   `path`, `origin_name`, `ext`,`up_time`,`up_user`,`up_type`) VALUES(  ?,?,?,?,?,? )  ";
        int count = super.update(sql,
                po.getPath(),
                po.getOriginName(),
                po.getExt(),
                po.getUpTime(),
                po.getUpUser(),
                po.getUpType()

        );


        //已保存 自动生成的id
        Long id = threadLocal.get();

        po.setUploadId(id.intValue());

        return count;

    }


    public int update(UploadPO po) {
        StringBuffer sql = new StringBuffer();

        sql.append(" update 					");
        sql.append("   `upload` 			");
        sql.append(" set			");
        sql.append("   `path` = ?,			");
        sql.append("   `origin_name` = ?,			");
        sql.append("   `ext` = ?,			");
        sql.append("   `up_time` = ?,			");
        sql.append("   `up_user` = ?,			");
        sql.append("   `up_type` = ?			");

        sql.append(" where `upload_id` =  ?			");


        int count = super.update(sql.toString(),
                po.getPath(),
                po.getOriginName(),
                po.getExt(),
                po.getUpTime(),
                po.getUpUser(),
                po.getUpType(),

                po.getUploadId()
        );

        return count;

    }

    /**
     * 通用的方法
     *
     * @return
     */

    public int delete(long id) {
        StringBuffer sql = new StringBuffer();

        sql.append(" delete from upload where upload_id = ?");

        int count = super.update(sql.toString(),   id        );

        return count;

    }


}
